<?php

namespace App\Admin\Traits;

trait staticMaps
{
    private static $cachedMaps = [];
    
    public static function setMaps($key_name = '', $value_name = '', $data = [])
    {
        static::$cachedMaps[$key_name . $value_name] = $data;
    }
    
    public static function getMaps($key_name = '', $value_name = '')
    {
        if (isset(static::$cachedMaps[$key_name . $value_name])) {
            return static::$cachedMaps[$key_name . $value_name];
        } else {
            try {
                $data = static::pluck($value_name, $key_name)->toArray();
            } catch (\Exception $e) {
                return false;
            }
            return static::$cachedMaps[$key_name . $value_name] = $data;
        }
    }
}
